package game.module.user.logic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.HallServer;
import game.entity.PlayingRole;
import game.module.user.bean.PlayerAddressBean;
import game.module.user.bean.PlayerBean;
import game.module.user.dao.PlayerDao;

public class PlayerDaoHelper {

	private static Logger logger = LoggerFactory.getLogger(PlayerDaoHelper.class);

	static class SingletonHolder {
		static PlayerDaoHelper instance = new PlayerDaoHelper();
	}

	public static PlayerDaoHelper getInstance() {
		return SingletonHolder.instance;
	}

	public void asyncUpdatePlayerBean(final PlayingRole playingRole) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().updatePlayerBean(playingRole.getPlayerBean());
			};
		});
	}

	public void asyncUpdatePlayerBean(final PlayerBean playerBean) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().updatePlayerBean(playerBean);
			};
		});
	}

	public void asyncAddJinDouForPlayerBean(final int id, long jinDouNum) {
		logger.info(" add jin dou num={},id={}", jinDouNum, id);
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().addJinDou(jinDouNum, id);
			};
		});
	}

	public void asyncPlayerBeanExitClub(final int playerId) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().exitClub(playerId);
			};
		});
	}

	public void asyncAddFangKa(int money, int playerId) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().addMoneyById(money, playerId);
			};
		});
	}

	public void asyncAddCoin(int addCoin, int playerId) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().addCoin(addCoin, playerId);
			};
		});
	}
	
	public void asyncAddOrUpdateAddress(PlayerAddressBean bean) {
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PlayerDao.getInstance().insertOrUpdateAddress(bean);
			};
		});
	}

}
